<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Banner;
use app\common\model\Coupon as ModelCoupon;
use app\common\model\coupon\Log;
use app\common\model\CouponLog;
use app\common\model\User;
use Exception;

/**
 * 优惠券接口
 */
class Coupon extends Api
{
    protected $noNeedLogin = ['list'];
    protected $noNeedRight = ['*'];


    /**
     * @Author LK
     * @date: 2024-01-16 
     * @ApiTitle (我的优惠券)
     * @ApiMethod (GET)
     * @ApiParams (name="type", type="string", required=true, sample="", description="0=已失效,1=未使用,2=已使用")
     * @ApiParams (name="limit", type="int", required=true, sample="", description="每页数量")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function myCoupon()
    {
        $get = request()->get();
        extract($get);
        if (!isset($type)) {
            $this->error('参数错误');
        }
        try {
            $user_id =  $this->auth->id;
            $couponLog = new CouponLog();
            $list = $couponLog->getUseCoupon($type, $user_id, $limit??10);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }

        $this->success('请求成功', $list);
    }
}
